#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Group < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_defualt_variables
    grp = M3G::Group.new
    
    assert_equal 0, grp.child_count
  end

  def test_set_variables
    grp  = M3G::Group.new
    grp1 = M3G::Group.new
    grp2 = M3G::Group.new
    grp.child << grp1
    grp.child << grp2

    assert_equal 2   , grp.child_count
    assert_equal grp1, grp.child[0]
    assert_equal grp2, grp.child[1]

    grp.remove_child grp1

    assert_equal 1, grp.child_count
    assert_equal grp2, grp.child[0]

    grp.remove_child grp2

    assert_equal 0, grp.child_count
  end

  def test_get_refrences
    grp  = M3G::Group.new
    grp1 = M3G::Group.new
    grp2 = M3G::Group.new
    grp.child << grp1
    grp.child << grp2

    refs = grp.references

    assert_equal 2   , refs.length
    assert_equal grp1, refs[0]
    assert_equal grp2, refs[1]
  end

  def test_pick

    # 実装されていない
    # m3g-viewerあたりでピックして確認する
  end

  def test_deplicate
    # parent --> grp0 --> child
    grp0   = M3G::Group.new;
    parent = M3G::Group.new;
    child  = M3G::Group.new;
    parent.child << grp0
    grp0.child   << child

    grp1   = grp0.duplicate

    # parent --> grp0 --> child
    #             | (duplicate)
    #      0 --> grp1 --> duplicated child

    # 子ノードも再起的にduplicate
    assert_equal 1, grp1.child_count

    # duplicateされた方のノードのparentはnilになる
    assert_equal parent, grp0.parent
    assert_equal nil   , grp1.parent

    # duplicateされrた方のノードのchildもduplicateされ、
    # それは元のchildと同じでならない
    assert_equal     child, grp0.child[0]
    assert_not_equal child, grp1.child[0]

    # duplicateされたノードは対応するRubyオブジェクトを持っていて
    # しかもトポロジーは壊れてない
    assert_equal grp1, grp1.child[0].parent

  end

end
